package com.mdd.admin.controller.coupon;

import com.google.gson.JsonObject;
import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.ICouponService;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.order.CouponCreateValidate;
import com.mdd.admin.validate.order.CouponIssuingValidate;
import com.mdd.admin.validate.order.CouponSearchValidate;
import com.mdd.admin.vo.coupon.CouponSettingVo;
import com.mdd.common.core.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 优惠券控制层
 *
 * @author shenjian
 * @createTime 2023年02月27日 21:59:00
 */
@RestController
@RequestMapping("api/coupon")
@CrossOrigin
public class CouponController {

    @Resource
    ICouponService iCouponService;

    /**
     * 优惠券基础设置查询
     *
     * @return AjaxResult<?>
     * @author shenjian
     */
    @Log(title = "优惠券基础设置")
    @GetMapping(value = "/getConfig")
    public AjaxResult<?> getConfig() {
        return AjaxResult.success(iCouponService.getConfig());
    }

    /**
     * 优惠券设置
     *
     * @param couponList
     * @return AjaxResult<PageResult < Object>>
     * @author shenjian
     */
    @Log(title = "优惠券基础设置")
    @PostMapping(value = "/config")
    public AjaxResult<Object> config(@Validated @RequestBody List<CouponSettingVo> couponList) {
        return iCouponService.config(couponList);
    }

    /**
     * 优惠券列表
     *
     * @param pageValidate   分页参数
     * @param searchValidate 搜索参数
     * @return AjaxResult<PageResult < Object>>
     * @author shenjian
     */
    @Log(title = "优惠券列表")
    @GetMapping(value = "/list")
    public AjaxResult<Object> list(@Validated PageValidate pageValidate,
                                   @Validated CouponSearchValidate searchValidate) {
        return AjaxResult.success(iCouponService.list(pageValidate, searchValidate));
    }

    /**
     * 优惠券创建
     *
     * @return AjaxResult<PageResult < Object>>
     * @author shenjian
     */
    @Log(title = "优惠券创建")
    @PostMapping(value = "/create")
    public AjaxResult<Object> create(@Validated @RequestBody CouponCreateValidate createValidate) {
        return AjaxResult.success(iCouponService.create(createValidate));
    }

    /**
     * 优惠券发放
     * @param issuingValidate
     * @return
     */
    @Log(title = "优惠券发放")
    @PostMapping(value = "/issuing")
    public AjaxResult<Object> issuing(@Validated @RequestBody CouponIssuingValidate issuingValidate) {
        return AjaxResult.success(iCouponService.issuing(issuingValidate));
    }
}